package com.leyou.redisdemo;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

@Slf4j
@RestController
@RequestMapping
public class RedisTest {

    @Autowired
    private RedisTemplate redisTemplate;
    @RequestMapping("/redis")
    public Object redisTest(){
//存取
//        redisTemplate.opsForValue().set("num1","123");
//        Object num = redisTemplate.opsForValue().get("num1");
// 重新给key赋值,同时返回原有value值
//        redisTemplate.opsForValue().set("getSetTest","test");
//        Object andSet = redisTemplate.opsForValue().getAndSet("getSetTest", "test2");
// 如果key已经存在并且是一个字符串，则该命令将该值追加到字符串的末尾。如果键不存在，则它被创建并设置为空字符串，因此APPEND在这种特殊情况下将类似于SET
//        redisTemplate.opsForValue().append("test","Hello");
//        redisTemplate.opsForValue().append("test","world");
//获取对应v的长度
//        Long key = redisTemplate.opsForValue().size("key");

//操作list,将val2放在val1前面的位置
redisTemplate.opsForList().leftPush("key1","val1","val2");
//list类型添加数据
redisTemplate.opsForList().leftPushAll("key1","v1","2",3,3);
        List<Integer> integers = Arrays.asList(1, 23, 45);
//        redisTemplate.opsForList()
        return null;
    }
}
